#!/bin/sh
#
# Initialize Service Agent
#

# Ensure that svcagent runs this script to prevent severe security risks
#id=`id`
#id=${id#*\(}
#id=${id%%\)*}
#if [ "$id" != "svcagent" ] && [ "$id" != "root" ]
#then
#  echo "$0: This script must be run by the user svcagent."
##  exit 1
#fi
#
# Ensure that X11 is installed.
#lslpp -ql 'X11.base.*' >/dev/null 2>&1
#if [ $? -ne 0 ]
#then
#  echo "$0: Graphical interface cannot be run; X11 windowing software not installed."
#  exit 1
#fi

# Ensure DISPLAY is set
#if [ -z "$DISPLAY" ]
#then
#  echo "$0: Display variable DISPLAY is not set."
#  exit 1
#fi

#if [ "$id" = "svcagent" ]
#then
#  c='ksh'
#else
#  c='ksh'
#fi
#
#$c <<\EOF
#
#unset CLASSPATH
#unset JAVA_HOME

for f in /usr/svcagent/lib/*jar
do
  export CLASSPATH=$CLASSPATH:$f
done

export PATH=$PATH:/usr/svcagent/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/local/bin:/usr/dt/bin:/opt/IBMJava2-13/jre/bin
#export JAVA_COMPILER=NONE
cd /var/svcagent


# Check if the License Agreement is Accepted by the user

if [ -f /var/svcagent/IBMLicense ]
then
  echo "$0: License Agreement is NOT YET Accepted by the user. Showing up the License Screen.."
#  java com.ibm.ecf.apps.LicenseAgreement
fi

sleep 2

# If the License Screen is already shown, check if it is accepted by the user or not

if [ ! -f /var/svcagent/IBMLicense.accept ]
then
  echo "$0: License is NOT accepted. Cannot Continue the Service Agent Program."
#  exit 1
fi

# Since it is required to show the License Screen each time, the following
# Command is added. Later it should be removed.

# mv /var/svcagent/IBMLicense.accept /var/svcagent/IBMLicense


bc=""
bc=`java com.ibm.ecf.apps.Bcp`
nohup java $bc com.ibm.sa.apps.SAINST > /var/svcagent/logs/log.sainst 2>&1 &
#nohup java $bc com.ibm.sa.apps.SAINST > /dev/null 2>&1 &

sleep 2
echo User Interface will appear shortly
